package com.fingard.dsp.bank.directbank.cmbunion01;

import com.alibaba.fastjson.JSONObject;
import com.fingard.dsp.bank.directConfig.ActSetItem;
import com.fingard.dsp.bank.directbank.bankInterface.ICloseOrder;
import com.fingard.dsp.bank.directbank.cmbunion01.util.BoingPay;
import com.fingard.dsp.bank.reqrespobj.closeorder.CloseOrderState;
import com.fingard.dsp.bank.reqrespobj.closeorder.ReqCloseOrder;
import com.fingard.dsp.bank.reqrespobj.closeorder.RetAtsCloseOrder;

public class CMBUnion01CloseOrder extends CMBUnion01Base implements ICloseOrder {

	@Override
	public RetAtsCloseOrder closeOrder(ReqCloseOrder p_req) {
		RetAtsCloseOrder retAts = new RetAtsCloseOrder(p_req.reqHeader);
		retAts.rdSeq = p_req.rdSeq;
		try {
			ActSetItem actItem = this.getBankConfig().getActSetItem(
					p_req.ownAct, "");
			if (actItem != null) {

				String[] RSApath = actItem.ownCertFilePath.split(",");
				setConfig(actItem.merchantId, bankFront.getUrl("unifiedPay"),
						RSApath[0], RSApath[1], actItem.ownKeyStorePath,
						actItem.oppCertFilePath, actItem.ownKeyPassword);

				WriteBankUrlLogLn(bankFront.getUrl("unifiedPay"));
				JSONObject ret = BoingPay.getCashier().close(p_req.ownAct,
						p_req.outTransID);
				WriteBankLogStep3("招商聚合关单返回：" + ret);
				retAts.respCode = "0";
				if (ret.getString("error_code") == null || ret.getString("error_code").equals("ACQ.TRADE_NOT_EXIST")) {
					retAts.closeState = CloseOrderState.Close_Success;
				} else {
					retAts.closeState = CloseOrderState.Close_Fail;
				}
			} else {
				retAts.respCode = "-1";
				retAts.respInfo = "未找到账号:[" + p_req.ownAct + "]相关商户配置信息!";
			}
		} catch (Exception ex) {
			retAts.respCode = "-1";
			retAts.respInfo = ex.getMessage();
			ex.printStackTrace();
			WriteBankLogLn(ex);
		}
		return retAts;
	}
}